libostree: Add ostree_async_progress_copy_state()
authorPhilip Chimento <philip@endlessm.com>
Mon, 4 Nov 2019 21:21:36 +0000 (13:21 -0800)
committerPhilip Chimento <philip@endlessm.com>
Wed, 20 Nov 2019 20:24:26 +0000 (12:24 -0800)
This allows copying the state from one OstreeAsyncProgress object to
another, atomically, without invoking the callback. This is needed in
libflatpak, in order to chain OstreeAsyncProgress objects so that you
can still receive progress updates when iterating a different
GMainContext than the one that the OstreeAsyncProgress object was
created under.

See https://github.com/flatpak/flatpak/pull/3211 for the application of
this API.

apidoc/ostree-sections.txt
src/libostree/libostree-devel.sym
src/libostree/ostree-async-progress.c
src/libostree/ostree-async-progress.h

index 252a563acba7216cb3d344ea261f5b908d52a4a7..f99c4df55f04d459427806bf9fb842056b195c4d 100644 (file)
@@ -3,6 +3,7 @@
 OstreeAsyncProgress
 ostree_async_progress_new
 ostree_async_progress_new_and_connect
+ostree_async_progress_copy_state
 ostree_async_progress_get_status
 ostree_async_progress_get
 ostree_async_progress_get_variant
index d9d0205665d44d0e73f3eca4952b71db7e12cb99..646a4a21a06123fdab01eaa46e3a5eaa223b504c 100644 (file)
@@ -19,6 +19,7 @@
 
 /* Add new symbols here.  Release commits should copy this section into -released.sym. */
 LIBOSTREE_2019.6 {
+  ostree_async_progress_copy_state;
 } LIBOSTREE_2019.4;
 
 /* Stub section for the stable release *after* this development one; don't
index 64372c271c0cafae7bfa4915fb22f992c3fbc556..8d6fdfe50e00a2083e47777a9a65f4ee499bbf5a 100644 (file)
@@ -424,6 +424,40 @@ ostree_async_progress_set_uint64 (OstreeAsyncProgress       *self,
   ostree_async_progress_set_variant (self, key, g_variant_new_uint64 (value));
 }
 
+/**
+ * ostree_async_progress_copy_state:
+ * @self: An #OstreeAsyncProgress to copy from
+ * @dest: An #OstreeAsyncProgress to copy to
+ *
+ * Atomically copies all the state from @self to @dest, without invoking the
+ * callback.
+ * This is used for proxying progress objects across different #GMainContexts.
+ *
+ * Since: 2019.6
+ */
+void
+ostree_async_progress_copy_state (OstreeAsyncProgress *self,
+                                  OstreeAsyncProgress *dest)
+{
+  g_return_if_fail (OSTREE_IS_ASYNC_PROGRESS (self));
+  g_return_if_fail (OSTREE_IS_ASYNC_PROGRESS (dest));
+
+  g_mutex_lock (&self->lock);
+
+  if (self->dead)
+    goto out;
+
+  GLNX_HASH_TABLE_FOREACH_KV (self->values, void *, key, GVariant *, value)
+    {
+      if (value)
+        g_variant_ref (value);
+      g_hash_table_replace (dest->values, key, value);
+    }
+
+ out:
+  g_mutex_unlock (&self->lock);
+}
+
 /**
  * ostree_async_progress_new:
  *
index 45a80cfb6ca6a40292e1d2a86f376dee627d62fb..475d7f62c56c888419fecfabdf81126c1568343e 100644 (file)
@@ -92,4 +92,8 @@ void ostree_async_progress_set_variant (OstreeAsyncProgress *self,
 _OSTREE_PUBLIC
 void ostree_async_progress_finish (OstreeAsyncProgress *self);
 
+_OSTREE_PUBLIC
+void ostree_async_progress_copy_state (OstreeAsyncProgress *self,
+                                       OstreeAsyncProgress *dest);
+
 G_END_DECLS